package org.example.coknown.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.example.coknown.entity.TraceabilityInformation;

import java.util.List;

@Mapper
public interface TraceabilityInformationMapper extends BaseMapper<TraceabilityInformation> {
    /**
     * 分页查询溯源信息
     */
    IPage<TraceabilityInformation> selectPage(Page<TraceabilityInformation> page);
    /**
     * 根据id查询溯源信息
     */
    @Select("select * from traceability_information where product_id = #{id}")
    List<TraceabilityInformation> selectById(Integer id);

    /**
     * 添加溯源信息
     */
    @Insert("insert into traceability_information(product_name,notes,staff_name,details,update_time,current_process,betch,produce_date,admin_name) values(#{productName},#{notes},#{staffName},#{details},#{updateTime},#{currentProcess},#{betch},#{produceDate},#{adminName})")
    int insert(TraceabilityInformation traceabilityInformation);

    /**
     * 根据betch查询溯源信息,成功返回查询信息，失败返回null
     */
    @Select("select * from traceability_information where betch = #{betch}")
    List<TraceabilityInformation> selectByBetch(Integer betch);
}
